<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="support.*, java.util.*, myclasses.*, java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Address</title>
</head>
<body>
<%
	String residence = request.getParameter("residence");
	Student stud = (Student)session.getAttribute("student");
	stud.setResidenceId(residence);
	String citName = "";
	String resName = "";
	try {
		Class.forName("org.postgresql.Driver");
	} catch(ClassNotFoundException e) {
		out.println("org.postgresql.Driver Exception. ");
	}

	try {
		String serverName = "localhost:5432";
	    String mydatabase = "ThirdBase";
	    String url = "jdbc:postgresql://" + serverName + "/" + mydatabase; 
	    String username = "SweetAss";
	    String password = "1234";
	    Connection conn = DriverManager.getConnection(url, username, password);
	    
		Statement stmt = conn.createStatement();
		ResultSet rset = stmt.executeQuery("SELECT name FROM country WHERE id = " + stud.getCitizenshipId() + " OR id = " + residence);
		
		rset.next();
		citName = rset.getString(1);
		if (!stud.getCitizenshipId().equals(residence)) {
	rset.next();
	resName = rset.getString(1);
		} else {
	resName = citName;
		}
		
		rset.close();
		stmt.close();
	    conn.close();
	    
	} catch (SQLException e) {
		e.printStackTrace();
		out.println("Connection exception.");
	}
%>

Name: <%= stud.getFirstName() %> <%= stud.getMiddleInitial() %>. <%= stud.getLastName() %>.<br>
Country of citizenship: <%= citName %>.<br>
County of residence: <%= resName %>.<br>


<form method="get" action="provideDegreesChooseLocation.jsp">
<%
//if the residence is from USA

//get vs post
if(residence != null) {
	if(residence.equals("213")) {
		out.println("Street: " + "<input type =\"text\" size=\"40\" name=\"street\" />" );
		out.println("<br>City: " + "<input type =\"text\" size=\"30\" name=\"city\" />" );
		out.println("<br>Sate: " + "<input type =\"text\" size=\"30\" name=\"state\" />" );
		out.println("<br>Zip code: " + "<input type =\"text\" size=\"5\" name=\"zip\" />" );
		out.println("<br>Area code:	" + "<input type =\"text\" size=\"4\" name=\"area\" />" );
		out.println("<br>Number: " + "<input type =\"text\" size=\"10\" name=\"number\" />" );
	} else {
		out.println("Country telephone code: " + "<input type =\"text\" size=\"5\" name=\"countryCode\" />" );
		out.println("<br>Street: " + "<input type =\"text\" size=\"40\" name=\"street\" />" );
		out.println("<br>City: " + "<input type =\"text\" size=\"30\" name=\"city\" />" );
		out.println("<br>Zip code: " + "<input type =\"text\" size=\"5\" name=\"zip\" />" );
		out.println("<br>Area code:	" + "<input type =\"text\" size=\"4\" name=\"area\" />" );
		out.println("<br>Number: " + "<input type =\"text\" size=\"10\" name=\"number\" />" );
	}
}
%>
<br>
<input type="submit" value="Submit"/>
</form>
</body>
</html>